package com.zyh.day02

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object TextFileTest {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
      .setMaster("local[*]")
      .setAppName("textFile")
    val sc = new SparkContext(conf)

    //2 读取文件,转换为RDD
    val fileRDD: RDD[String] = sc.textFile("hdfs://hadoop10:9000/sparktest/words.txt")
    println(fileRDD.getNumPartitions)

    //3 调用转换算子
    val rdd2: RDD[String] = fileRDD.flatMap(item => item.split("\\s+"))

    //4 调用行动算子
    val result: Array[String] = rdd2.collect()
    result.foreach(println)

    //5 关闭资源
    sc.stop()
  }
}
